//
//  InProgressConstructPositionView.m
//  RunOneZhangLu
//
//  Created by runone02 on 17/3/8.
//  Copyright © 2017年 runone. All rights reserved.
//  施工地点的view

#import "InProgressConstructPositionView.h"
#import "SDAutoLayout.h"
#import "UIView+Addition.h"

@interface InProgressConstructPositionView ()


           
@property (nonatomic, copy)   NSString *leftTitleStr;    //左边标题
@property (nonatomic, assign) BOOL isBtnCanTouch;

@end


@implementation InProgressConstructPositionView

#pragma mark - lazyLoad

- (InProgressConstructPositionView *) initWithDefalutHeight:(CGFloat) height title:(NSString *)titleStr isCanTouch:(BOOL)isCan{
    _leftTitleStr  = titleStr;
    _isBtnCanTouch = isCan;
    return [self initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, height)];
}


-(instancetype)initWithFrame:(CGRect)frame {
    self=[super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor colorWithRed:226.0 / 255 green:230.0 / 255 blue:240.0 / 255 alpha:1]];
        
        [self configUI];
        [self layoutUI];
    }
    return self;
}

- (void) configUI {
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.font = [UIFont systemFontOfSize:15];
    _titleLabel.textAlignment = NSTextAlignmentRight;
    _titleLabel.text = _leftTitleStr;
    
    _middelBtn = [[UIButton alloc] init];
    _middelBtn.backgroundColor = [UIColor clearColor];
    
    _middelLabel = [[UILabel alloc] init];
    _middelLabel.font = [UIFont systemFontOfSize:15];
    _middelLabel.textColor = [UIColor blackColor];
    _middelLabel.backgroundColor          = _isBtnCanTouch ? [UIColor whiteColor] : [UIColor clearColor];
    _middelBtn.enabled                  = _isBtnCanTouch;
    
    _rightBtn = [[UIButton alloc] init];
    _rightBtn.backgroundColor = [UIColor clearColor];
    
    _rightLabel = [[UILabel alloc] init];
    _rightLabel.font = [UIFont systemFontOfSize:15];
    _rightLabel.textColor = [UIColor blackColor];
    _rightLabel.backgroundColor          = _isBtnCanTouch ? [UIColor whiteColor] : [UIColor clearColor];
    _rightBtn.enabled                  = _isBtnCanTouch;
    
    _lineView   = [UIView new];
    _lineView.backgroundColor = [UIColor whiteColor];
    
    _verticalLineV = [UIView new];
    _verticalLineV.backgroundColor = [UIColor blackColor];
    
    [self sd_addSubviews:@[self.titleLabel, self.middelBtn, self.lineView, self.rightBtn, self.verticalLineV,self.middelLabel, self.rightLabel]];
}

- (void) layoutUI {

    self.titleLabel.sd_layout
    .leftSpaceToView(self, 0)
    .topSpaceToView(self, 10)
    .heightIs(34)
    .widthIs(110)
    ;
    
    self.middelBtn.sd_layout
    .leftSpaceToView(self.titleLabel, 8)
    .widthIs(([UIScreen mainScreen].bounds.size.width - 110 - 16 - 11) / 2)
    .topSpaceToView(self, 8)
    .heightIs(34);
    ;
    
    self.middelLabel.sd_layout
    .leftSpaceToView(self.titleLabel, 8)
    .widthIs(([UIScreen mainScreen].bounds.size.width - 110 - 16 - 11) / 2)
    .topSpaceToView(self, 10)
    .heightIs(34);
    ;
    
    self.verticalLineV.sd_layout
    .leftSpaceToView(self.middelBtn, 5)
    .rightSpaceToView(self.rightBtn, 5)
    .widthIs(1)
    .topEqualToView(self.middelBtn)
    .heightIs(self.middelBtn.height)
    ;
    
    self.rightBtn.sd_layout
    .leftSpaceToView(self.middelBtn, 10)
    .widthIs(([UIScreen mainScreen].bounds.size.width - 110 - 16 - 11) / 2)
    .topSpaceToView(self, 8)
    .heightIs(34);
    ;
    
    self.rightLabel.sd_layout
    .leftSpaceToView(self.middelBtn, 10)
    .widthIs(([UIScreen mainScreen].bounds.size.width - 110 - 16 - 11) / 2)
    .topSpaceToView(self, 10)
    .heightIs(34);
    ;

    self.lineView.sd_layout
    .leftSpaceToView(self, 8)
    .rightSpaceToView(self, 8)
    .heightIs(1)
    .topSpaceToView(self.titleLabel, 8)
    ;
    
    [self setupAutoHeightWithBottomView:self.lineView bottomMargin:0];
}
#pragma mark -  设置
- (void) setMiddelString:(NSString *)middelStr rightString:(NSString *)rightStr {
    _middelLabel.textColor = [UIColor blackColor];
    _rightLabel.textColor = [UIColor blackColor];
    self.middelLabel.text = middelStr;
    self.rightLabel.text  = rightStr;
}

- (void) updateMyLayout {
//    UIView *view = [_rightLabel.text length] > [_middelLabel.text length] ? _rightLabel : _middelLabel;
//    self.lineView.sd_layout
//    .leftSpaceToView(self, 8)
//    .rightSpaceToView(self, 8)
//    .heightIs(1)
//    .topSpaceToView(view, 10)
//    ;
}


@end
